import storage from '../../utils/storage';
import utils from '../../utils';

export default {
  namespaced: true, // 启用命名空间
  state: {
    userInfo: {},
    token: ''
  },
  getters: {
    getUser: state => {
      return utils.replaceInvalidValue(state.userInfo, storage.get('userInfo'))
    },
    getToken: state => {
      return utils.replaceInvalidValue(state.token, storage.get('token'))
    }
  },
  mutations: {
    setUser(state, payload) {
      state.userInfo = payload;
      storage.set('userInfo', payload)
    },
    clearUser: (state) => {
      state.userInfo = {}
      storage.remove('userInfo');
    },
    clearToken: (state) => {
      state.token = {}
      storage.remove('token');
    },
  },
  actions: {
    fetchUser({ commit }) {
      /*...*/
    }
  }
}